package com.nuc.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Time    : 2023/3/30 15:13
 * Author  : 王摇摆
 * FileName: Output.java
 * Software: IntelliJ IDEA 2020.2.2
 * Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
 */

public class Output {
    public static void main(String[] args) {
        Map<Integer, String> gameMap = new HashMap<>();

        gameMap.put(1, "守望先锋");
        gameMap.put(2, "守望先锋2");
        gameMap.put(3, "穿越火线");

        //遍历集合：1. 由键找值，创建键的集合
        Set<Integer> number = gameMap.keySet();
        for (Integer numerKey : number) {
            String value = gameMap.get(numerKey);
            System.out.println(numerKey + " " + value + " ");
        }
        System.out.println("-----------");

        //遍历集合：2. 拿到所有键值对的集合来输出
        Set<Map.Entry<Integer, String>> entrySet = gameMap.entrySet();

        for (Map.Entry<Integer, String> me : entrySet) {
            Integer key = me.getKey();
            String value = me.getValue();
            System.out.println(key + " " + value + " ");
        }
        System.out.println("-----------");
    }
}
